﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
///离线状态下角色控制
/// </summary>
public class OfflinePlayerContol : MonoBehaviour
{
   // public Transform CameraChild;
    private CharacterController cc;//

    public float moveSpeed = 7;//角色移动速度

    private float horizontalMove, verticalMove;//按键值变量

    private Vector3 dir;//定义三维变量,dir控制方向

    private void Start()
    {
        cc = GetComponent<CharacterController>();
        /*
        if(NetState.isNet == false)
        {
            Camera.main.transform.SetParent(transform);
            Camera.main.transform.localPosition = Vector3.zero;
        }
        */
    }
    void Update()
    {
        if (NetState.isNet == false)//离线模式角色控制
        {
            //CameraChild.parent = this.transform;
            print("离线模式");
            if (Input.GetKeyDown(KeyCode.F))
            {
                GameObject.Find("Camera").GetComponent<PlayerCameraControl>().enabled = false;
            }
            if (Input.GetKeyDown(KeyCode.T))
            {
                GameObject.Find("Camera").GetComponent<PlayerCameraControl>().enabled = true;
            }
            horizontalMove = Input.GetAxis("Horizontal") * moveSpeed;
            verticalMove = Input.GetAxis("Vertical") * moveSpeed;

            //dir储存移动的方向
            dir = transform.forward * verticalMove + transform.right * horizontalMove;
            cc.Move(dir * Time.deltaTime);

        }
    
    }
}
